<!--  -->
<template>
  <div class="update-gender">
    <van-picker
    show-toolbar
    :columns="columns"
    :default-index="defaultIndex"
    @cancel="$emit('close')"
    @confirm="onConfirm"
  />
  </div>
</template>

<script>
import { updateUserProfile } from '@/api/user'
export default {
  name:'UpdateGender',
  components: {},
  props:{
    value:{
      type:Number,
      require:true
    }
  },
  data () {
  return {
         columns:['男','女'],
         defaultIndex:this.value
    }
  },
  computed: {},
  watch: {},
  created() {},
  mounted(){},
  methods: {
     async onConfirm(value, index){

    
     this.$toast.loading({
       message:'保存中',
       forbidClick:true  //禁止背景点击
     })

     try {
       const {data}=await updateUserProfile({
       gender:index
     })
      this.$toast.success('保存成功')
      // this.$emit('update-name',this.localName)
      this.$emit('input',index)
     //更新成功->修改父组件->关闭弹出层
     this.$emit('close')
       
     } catch (error) {
         if(error&&error.response){
            this.$toast.fail(error.response.data)
         }
     }
     
    }
  }
}

</script>
<style lang='less' scoped>
</style>